package com.thinkcar.knife4j.config;

import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * OpenAPI 配置类
 * 基于OpenAPI-3.0规范 + SpringDoc + knife4j增强
 *
 * @author jy
 * @since 3.0.0
 */
@Configuration
@RequiredArgsConstructor
@EnableConfigurationProperties(Knife4jInfoProperties.class)
public class Knife4jConfig {

    /**
     * API 文档信息属性
     */
    private final Knife4jInfoProperties knife4jInfoProperties;


    /**
     * OpenAPI 配置（元信息、安全协议）
     */
    @Bean
    public OpenAPI apiInfo() {
        return new OpenAPI()
                // 接口文档信息(不重要)
                .info(new Info()
                        .title(knife4jInfoProperties.getTitle())
                        .version(knife4jInfoProperties.getVersion())
                        .description(knife4jInfoProperties.getDescription())
                        .contact(new Contact()
                                .name(knife4jInfoProperties.getContact().getName())
                                .url(knife4jInfoProperties.getContact().getUrl())
                                .email(knife4jInfoProperties.getContact().getEmail())
                        )
                        .license(new License().name(knife4jInfoProperties.getLicense().getName())
                                .url(knife4jInfoProperties.getLicense().getUrl())
                        ));
    }

}
